<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Choose Materials for Cooking</title>

<script type="text/javascript">
function process_picking() {
	var selectedFoods = document.getElementsByName('selectedFoods');
	var selectedFoods_str = '';
	for (var i = 0; i < selectedFoods.length; i++) {
		if (selectedFoods[i].checked) {
	   		selectedFoods_str += selectedFoods[i].value + ',';
		}
	}
	if (selectedFoods_str != '') {
		selectedFoods_str = selectedFoods_str.substring(0, selectedFoods_str.length - 1);
	}
	window.opener.document.getElementById("foods_str").value = selectedFoods_str;
	window.close();
}
</script>

</head>
<body>
	<h3>Choose food material</h3>
	<c:set var="dishDTO" value="${requestScope.DISHDTO}"></c:set>
	<c:forEach var="foodDTO" items="${requestScope.FOODLIST}">
		<c:set var="checker" value="false"></c:set>
		<c:forEach var="selectedFoodDTO" items="${dishDTO.foodList}">
			<c:if test="${selectedFoodDTO.id == foodDTO.id}">
        		<c:set var="checker" value="true"></c:set>
        		
    		</c:if>
		</c:forEach>
		<c:if test="${checker eq 'true'}">
			<input type="checkbox" id="${foodDTO.id}" name="selectedFoods" value="${foodDTO.id}" checked/>${foodDTO.name}<br/>
		</c:if>
		<c:if test="${checker eq 'false'}">
			<input type="checkbox" id="${foodDTO.id}" name="selectedFoods" value="${foodDTO.id}"/>${foodDTO.name}<br/>
		</c:if>
	</c:forEach>
	<input type="button" id="btnProcess" onclick="process_picking()" value="Save"/>
	<input type="button" onclick="top.close()" value="Return back"/>
</body>
</html>